package app.vendorportal.web.controller;

import app.vendorportal.service.PassportService;
import core.framework.web.site.cookie.RequireCookie;
import core.framework.web.site.scheme.HTTPSOnly;
import core.framework.web.site.session.RequireSession;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.inject.Inject;
import java.util.Map;

/**
 * @author Vince
 */
@HTTPSOnly
@RequireSession
@RequireCookie
@Controller
public class LoginController extends VendorPortalSiteController {

    private PassportService passportService;

    private String photoServerUrl;

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login(@RequestParam(value = "preRequestUrl", required = false) String preRequestUrl, Map<String, Object> model) {
//        if (loggedIn()) {
//            return "redirect:" + (StringUtils.hasText(securityValidator.validateRedirectUrl(preRequestUrl)) ? preRequestUrl : "/home");
//        }
//        if (StringUtils.hasText(preRequestUrl)) {
//            model.put("preRequestUrl", preRequestUrl);
//        }
        return "passport/login";
    }


    @RequestMapping(value = "/passport/forgetpassword", method = RequestMethod.GET)
    public String forgetPassword(Map<String, Object> model) {
        return "/passport/forgetpassword";
    }


    @Inject
    public void setPhotoServerUrl(@Value("${photo.server.url}") String photoServerUrl) {
        this.photoServerUrl = photoServerUrl;
    }

    @RequestMapping(value = "/signout", method = RequestMethod.GET)
    public String signout(Map<String, Object> model) {
        signOut();
        return "/passport/login";
    }

    @Inject
    public void setPassportService(PassportService passportService) {
        this.passportService = passportService;
    }

}
